﻿using Newtonsoft.Json;
using Sustainalytics.FileManager;
using Sustainalytics.LongRunningTaskManager.Interface;
using System;
using System.Linq;

namespace Sustainalytics.LongRunningTaskManager.Tests
{
    public class MyTaskUpload : MyTaskBase
    {
        private static IFileManager _fileManager = new DiskFileManager("TaskResult");

        public override Interface.LongRunningTaskTypeEnum Type
        {
            get { return (LongRunningTaskTypeEnum)1008; }
        }

        public override object Start(LongRunningTaskContext context)
        {
            base.Start(context);

            // deserialize params
            FileManagerFileTaskParam param = JsonConvert.DeserializeObject<FileManagerFileTaskParam>(context.ParamJson);

            if (param == null || param.FileManagerFilePaths == null || param.FileManagerFilePaths.Length == 0)
            {
                throw new InvalidOperationException("No files.");
            }

            // get files from file manager
            param.FileManagerFilePaths.ToList().ForEach(filePath =>
                {
                    FileContents fileContents = _fileManager.GetFile(filePath);
                });            

            return true;
        }
    }
}
